﻿@page "/CustomerRelationships"
@using CarlifeService;
@using Commonality.DTO;
@using ICarlifeService;
@using Models;
@inject NavigationManager NavigationManager
@inject IKeHuGuanXi services;
@using BootstrapBlazor.Components;

<PageTitle>客户关系管理</PageTitle>
   


<h3>客户关系管理</h3>
<EditForm Model=@guans>
        <div class="input-group mb-3">
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">客户名称：</span>
        </div>
        <InputText @bind-Value=ClientName class="form-control;input-group-prepend" aria-describedby="inputGroup-sizing-default"></InputText>
        <ValidationMessage For="@(() =>ClientName)" />
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">    联系电话：</span>
        </div>
        <InputText @bind-Value=Phone class="form-control;input-group-prepend" aria-describedby="inputGroup-sizing-default"></InputText>
        <ValidationMessage For="@(() =>Phone)" />
        <div class="input-group-prepend">
                        <span class="input-group-text" id="inputGroup-sizing-default">   身份证号：</span>
                    </div>
        <InputText @bind-Value=IdNumber class="form-control;input-group-prepend" aria-describedby="inputGroup-sizing-default"></InputText>
                    <ValidationMessage For="@(() =>IdNumber)" />

        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">   起租日期：</span>
        </div> 
        <input @bind="StartTime" type="date" />——
        <input @bind="EndTime" type="date" />
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">   客户类型：</span>
        </div>
        <select @bind="ClientTypeId">
            <option value="0">请选择</option>
            <option value="1">个人客户</option>
            <option value="2">企业客户</option>
        </select>
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">   风险等级：</span>
        </div>
        <select @bind="RankId">
            <option value="0">请选择</option>
            <option value="3">A级</option>
            <option value="4">B级</option>
            <option value="5">C级</option>
            <option value="6">D级</option>
        </select>
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">   客户进度：</span>
        </div>
        <select @bind="Progress">
            <option value="0">请选择</option>
            <option value="7">申请中</option>
            <option value="8">还款中</option>
            <option value="9">已完成</option>
        </select>
        <div class="input-group-prepend">
            <span class="input-group-text" id="inputGroup-sizing-default">   是否逾期：</span>
        </div>
        <select @bind="Isoverdueid">
            <option value="">请选择</option>
            <option value="是">是</option>
            <option value="否">否</option>
        </select>
    </div>
    <button id="search" class="btn btn-outline-secondary" @onclick="show">查询</button>
    <button id="search" class="btn btn-outline-secondary" @onclick="cz">重置</button>
           
    </EditForm>

<div>
    <table class="table-responsive" width="90%">
        <tr>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">客户Id</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">客户名称</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">联系电话</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">类型名称</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">身份证号</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">风险等级</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">业务进度</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">历史契约数</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">累计逾期次数</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">是否逾期</td>
            <td style="text-align:center;border:1px solid;padding:35px;background-color:#e9ecef">操作</td>
        </tr>

        @foreach (var item in guans)
        {
            <tr>
                <td style="text-align:center;border:1px solid;padding:35px;" >
                    <div @onclick="() => tz(Convert.ToString(item.Id))" style="color:blue">
                        @Convert.ToString(item.ClientId)
                    </div>
                </td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.ClientName</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.Phone</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.TypeName</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.IdNumber</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.NumberofOverduesName</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.NumberofContractsNamer</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.NumberofContracts</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.NumberofOverdues</td>
                <td style="text-align:center;border:1px solid;padding:35px;">@item.Isoverdueid</td>

                <td style="border:1px solid">
                    <a @onclick="() => Edit(Convert.ToString(item.Id))">编辑</a>

                    <a href="/AddBook?Id=@item.Id">日志</a>
                </td>
            </tr>

        }
   
    </table>

   




    </div>



@code {




    public DateTime? StartTime { get; set; }
    public DateTime? EndTime { get; set; }

    public int NumberofOverduesName { get; set; }
    public string TypeName { get; set; }
    public string NumberofContractsNamer { get; set; }
    public string Isoverdueid { get; set; }
    public string ClientName { get; set; }
    public string Phone { get; set; }
    public string IdNumber { get; set; }
    public int ClientTypeId { get; set; }
    public int RankId { get; set; }
    public int Progress { get; set; }
    public int size { get; set; }
    public int lendx { get; set; }


    private List<ClientDTO> guans;

   

    protected override async Task OnInitializedAsync()
    {
        guans = services.Shows(StartTime,EndTime,
            //size ,lendx ,
            ClientName ,  Phone , IdNumber,ClientTypeId , RankId , Progress , Isoverdueid );
        await base.OnInitializedAsync();
    }
    public void show()
    {
        guans = services.Shows(StartTime, EndTime,
            //size, lendx, 
            ClientName, Phone, IdNumber, ClientTypeId, RankId, Progress, Isoverdueid);
    }
    public void tz(string id)
    {
        NavigationManager.NavigateTo($"ClientDetail/{id}");
    }
    public void Edit(string id)
    {
        NavigationManager.NavigateTo($"Revise/{id}");
    }
    public void cz()
    {
        ClientName = "";
        Phone = "";
        IdNumber = "";
        RankId = 0;
        ClientTypeId = 0;
        Progress = 0;
        Isoverdueid = "";
        StartTime = null;
        EndTime = null;
        guans = services.Shows(StartTime, EndTime,
            //size, lendx, 
            ClientName, Phone, IdNumber, ClientTypeId, RankId, Progress, Isoverdueid);
    }
}
